﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


public enum Hand
{
    rock,
    paper,
    scissors,
    lizard,
    spock
}
/// <summary>
/// Using enum with five possible combinations-Rock,paper,Scissors,lizard,spock
/// Game is 2 wins out of 3 plays
/// input string with one of the names(catch exception)
/// difficulty is how much the computer wins
/// random generator to choose from enum
/// </summary>
class RockPaperLizard : Game
{

    string PlayerHand, AIHand;
    int Loses = 0, Wins = 0;
    Random rand = new Random();
    bool End = false;//
    public RockPaperLizard(int diff)
        : base(diff)
    {

    }
    public override void StartGame()//start of game
    {
        Explain();
        Sequence();


    }
    private void InputAnswer()//Getting input from user
    {
        Console.Write("Please choose your hand(lizard,spock,paper,scissors and rock): ");
        PlayerHand = Console.ReadLine();
        PlayerHand.ToLower();
    }
    private void Sequence()//Playing sequence of games
    {
        CheckForEnd();
        while (End == false)
        {
            InputAnswer();
            RandomHand();
            GameLogic();
            Sequence();
        }

    }
    private void CheckForEnd()//Checking for end condition
    {
        if ((Wins == 2) || (Loses == 2))
        {
            End = true;
            EndGame();
        }
    }
    public override void EndGame()//Displaying result and setting score
    {
        if (Wins == 2)
        {
            Console.WriteLine("Congratulations you beated the computer");
            Console.WriteLine("For your victory your result is 100 points");
            result = 100;
            Console.WriteLine("To continue press any key");
            Console.ReadKey();
        }
        else if (Wins == 1)
        {
            Console.WriteLine("Sorry but you lost,but dont feel too bad");
            Console.WriteLine("For your performance your result is 50 points");
            result = 50;
            Console.WriteLine("To continue press any key");
            Console.ReadKey();

        }
        else if (Wins == 0)
        {
            Console.WriteLine("Sorry but you suffered a crushing defeat");
            Console.WriteLine("For your performance your result is 10 points");
            result = 10;
            Console.WriteLine("To continue press any key");
            Console.ReadKey();

        }
    }
    private void RandomHand()//Getting random hand from enum
    {
        switch (rand.Next(0, 5))
        {
            case 0: AIHand = Hand.lizard.ToString();
                break;
            case 1: AIHand = Hand.paper.ToString();
                break;
            case 2: AIHand = Hand.rock.ToString();
                break;
            case 3: AIHand = Hand.scissors.ToString();
                break;
            case 4: AIHand = Hand.spock.ToString();
                break;
        }

    }
    private void Explain()//Startup screen of the game
    {
        Console.WriteLine("You will play several games agains the computer");
        Console.WriteLine("The first to win 2 is the winner");
        Console.WriteLine("There are 5 hands:lizard,spock,paper,scissors and rock");
        Console.WriteLine("For more info check the Help menu");
        Console.WriteLine("Press any key to continue to the game");
        Console.ReadKey();
    }
    private void GameLogic()//Checking if the hand is winning,losing or it is a tie
    {
        if (PlayerHand == "lizard")
        {
            if (AIHand == "spock" || AIHand == "paper")
            {
                Console.WriteLine("Congratulations you win this round");
                Console.WriteLine("To continue to next round press any key");
                Wins++;
                Console.ReadKey();
                //      Sequence();
            }
            if (AIHand == "scissors" || AIHand == "rock")
            {
                Console.WriteLine("The computer wins this round with hand:{0}",AIHand);
                Console.WriteLine("To continue to next round press any key");
                Loses++;
                Console.ReadKey();
                //    Sequence();
            }
            if (AIHand == "lizard")
            {

                Console.WriteLine("It is a draw");
                Console.WriteLine("To continue to next round press any key");
                Console.ReadKey();
                //  Sequence();
            }
        }

        if (PlayerHand == "spock")
        {
            if (AIHand == "lizard" || AIHand == "paper")
            {
                Console.WriteLine("The computer wins this round with hand:{0}",AIHand);
                Console.WriteLine("To continue to next round press any key");
                Loses++;
                Console.ReadKey();
                //Sequence();
            }
            if (AIHand == "scissors" || AIHand == "rock")
            {

                Console.WriteLine("Congratulations you win this round");
                Console.WriteLine("To continue to next round press any key");
                Wins++;
                Console.ReadKey();
                //   Sequence();
            }
            if (AIHand == "spock")
            {

                Console.WriteLine("It is a draw");
                Console.WriteLine("To continue to next round press any key");
                Console.ReadKey();
                // Sequence();
            }
        }

        if (PlayerHand == "scissors")
        {
            if (AIHand == "lizard" || AIHand == "paper")
            {
                Console.WriteLine("Congratulations you win this round");
                Console.WriteLine("To continue to next round press any key");
                Wins++;
                Console.ReadKey();
                //Sequence();

            }
            if (AIHand == "spock" || AIHand == "rock")
            {
                Console.WriteLine("The computer wins this round with hand:{0}", AIHand);
                Console.WriteLine("To continue to next round press any key");
                Loses++;
                Console.ReadKey();
                //Sequence();
            }
            if (AIHand == "scissors")
            {
                Console.WriteLine("It is a draw");
                Console.WriteLine("To continue to next round press any key");
                Console.ReadKey();
                //Sequence();
            }
        }
        if (PlayerHand == "paper")
        {
            if (AIHand == "spock" || AIHand == "rock")
            {
                Console.WriteLine("Congratulations you win this round");
                Console.WriteLine("To continue to next round press any key");
                Wins++;
                Console.ReadKey();
                //Sequence();

            }
            if (AIHand == "lizard" || AIHand == "scissors")
            {
                Console.WriteLine("The computer wins this round with hand:{0}", AIHand);
                Console.WriteLine("To continue to next round press any key");
                Loses++;
                Console.ReadKey();
                //Sequence();
            }
            if (AIHand == "paper")
            {
                Console.WriteLine("It is a draw");
                Console.WriteLine("To continue to next round press any key");
                Console.ReadKey();
                //Sequence();
            }
        }

        if (PlayerHand == "rock")
        {
            if (AIHand == "lizard" || AIHand == "scissors")
            {
                Console.WriteLine("Congratulations you win this round");
                Console.WriteLine("To continue to next round press any key");
                Wins++;
                Console.ReadKey();
                //Sequence();

            }
            if (AIHand == "paper" || AIHand == "spock")
            {
                Console.WriteLine("The computer wins this round with hand:{0}", AIHand);
                Console.WriteLine("To continue to next round press any key");
                Loses++;
                Console.ReadKey();
                //Sequence();
            }
            if (AIHand == "rock")
            {
                Console.WriteLine("It is a draw");
                Console.WriteLine("To continue to next round press any key");
                Console.ReadKey();
                //Sequence();
            }
        }

    }
}


